package net.kuratkoo.jidelnicekvut;

import java.io.IOException;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class XML {
    public static final String TAG = "JidelnicekVUT|XML";

    public static Document stringToXml(String s) throws SAXException, IOException, ParserConfigurationException {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(new InputSource(new StringReader(s)));
    }

    public static String getValue(Element e, String name) {
        NodeList nl = e.getElementsByTagName(name);
        Element el = (Element) nl.item(0);
        return el.getFirstChild().getNodeValue();
    }

}
